import React, { FC } from 'react'
import { ButtonProps, getButtonClassNames } from './config'

export const Button: FC<ButtonProps> = props => {
  const {
    disabled,
    className,
    size,
    btnType,
    children,
    href,
    ...restProps // 建议只将原生属性放在这里
  } = props
  // 添加btn前缀 btn、btn-large、btn-primary
  const btnClasses = getButtonClassNames(props)
  if (btnType === 'link' && href) {
    return (
      <a href={href} className={btnClasses} {...restProps}>
        {children}
      </a>
    )
  } else {
    return (
      <button className={btnClasses} disabled={disabled} {...restProps}>
        {children}
      </button>
    )
  }
}
Button.defaultProps = {
  disabled: false,
  btnType: 'default',
}
export default Button
